﻿// -------------------------------------------------------------------------
//    @FileName         :    NFPart.cpp
//    @Author           :    gaoyi
//    @Date             :    22-10-31
//    @Email			:    445267987@qq.com
//    @Module           :    NFPart
//
// -------------------------------------------------------------------------

#include "NFComm/NFPluginModule/NFCheck.h"
#include "NFLogicCommon/NFLogicShmTypeDefines.h"
#include "NFPart.h"
#include "NFPlayer.h"
#include "NFPartModule.h"

NFPart::NFPart()
{
    if (EN_OBJ_MODE_INIT == NFShmMgr::Instance()->GetCreateMode())
    {
        CreateInit();
    }
    else
    {
        ResumeInit();
    }
}

NFPart::~NFPart()
{
}

int NFPart::CreateInit()
{
    m_iPlayerObjId = INVALID_ID;
    m_pPlayer = nullptr;
    m_partType = 0;
    return 0;
}

int NFPart::ResumeInit()
{
    m_pPlayer = nullptr;
    return 0;
}

int NFPart::Init(NFPlayer *pMaster, uint32_t partType)
{
    CHECK_NULL(0, pMaster);
    m_pPlayer = pMaster;
    m_roleId = pMaster->GetRoleID();
    m_iPlayerObjId = pMaster->GetGlobalId();
    m_partType = partType;

    return 0;
}

int NFPart::UnInit()
{
    return 0;
}

int NFPart::RegisterClientMessage(uint32_t nMsgID, bool createCo)
{
    return FindModule<NFPartModule>()->RegisterClientServiceMessage(NF_ST_LOGIC_SERVER, nMsgID, m_partType, createCo);
}

int NFPart::RegisterServerMessage(uint32_t nMsgID, bool createCo)
{
    return FindModule<NFPartModule>()->RegisterServerServiceMessage(NF_ST_LOGIC_SERVER, nMsgID, m_partType, createCo);
}


int NFPart::OnHandleClientMessage(uint32_t msgId, NFDataPackage &packet)
{
    NFLogError(NF_LOG_DEFAULT, m_pPlayer->GetRoleID(), "client part package not handle:{}", packet.ToString());
    return 0;
}

int NFPart::OnHandleServerMessage(uint32_t msgId, NFDataPackage &packet)
{
    NFLogError(NF_LOG_DEFAULT, m_pPlayer->GetRoleID(), "server part package not handle:{}", packet.ToString());
    return 0;
}

uint32_t NFPart::GetCurRoleDetailSeq() const
{
    return GetCurSeq();
}

int NFPart::RegisterMessage()
{
    return 0;
}

NFPlayer* NFPart::GetPlayer()
{
    if (m_pPlayer == nullptr)
    {
        m_pPlayer = NFPlayer::GetObjByGlobalId(m_iPlayerObjId);
    }
    return m_pPlayer;
}

const NFPlayer* NFPart::GetPlayer() const
{
    if (m_pPlayer == nullptr)
    {
        const_cast<NFPart*>(this)->m_pPlayer = NFPlayer::GetObjByGlobalId(m_iPlayerObjId);
    }
    return m_pPlayer;
}


int NFPart::MakePlayerDataCS(proto_ff::Proto_CSGetRoleRsp* pCSGetRoleRsp)
{
    return 0;
}

int NFPart::MakeCityPlayerData(proto_ff::CityRoleInfo* pGCCityRoleInfo)
{
    return 0;
}